package cn.yanglei.crm.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.crm.domain.Customer;
import cn.yanglei.crm.dao.CustomerDao;
import cn.yanglei.crm.service.CustomerService;
@Service
@Transactional
public class CustomerServiceImpl implements CustomerService{
	@Autowired
	private CustomerDao customerDao;

	public List<Customer> findNoAssociationCustomoers() {
		return customerDao.findByFixedAreaIdIsNull();
	}

	public List<Customer> findHasAssociationFixedAreaCustomers(String fixedAreaId) {
		return customerDao.findByFixedAreaId(fixedAreaId);
	}

	public void associationCustomersToFixedArea(String customerIdStr, String fixedAreaId) {
		customerDao.clearFixedAreaID(fixedAreaId);
		if ("null".equalsIgnoreCase(customerIdStr)) {
			return;
		}
		String[] str = customerIdStr.split(",");
		for (String ids : str) {
			Integer id = Integer.parseInt(ids);
			customerDao.updateFixedAreaId(fixedAreaId,id);
		}
	}

	@Override
	public void regist(Customer customer) {
		customerDao.save(customer);
	}

	@Override
	public Customer findByTelephone(String telephone) {
		return customerDao.findByTelephone(telephone);
	}

	@Override
	public void updateType(String telephone) {
		 customerDao.updatetype(telephone);
	}

}
